﻿using System;
using System.Collections.Generic;
using System.Text;
using TarreOA.TarreOAModels;
using TarreOA.TarreOADAL;

namespace TarreOA.TarreOABLL
{
    public class UserCommunicationGrouptbService
    {
        /// <summary>
        /// 保存新建通讯组信息
        /// </summary>
        /// <param name="comGroupName"></param>
        /// <param name="comGroupType"></param>
        /// <param name="UserLoginName"></param>
        /// <param name="createTime"></param>
        /// <returns></returns>
        public bool saveComGroupInfo(string comGroupName, string comGroupType, string userLoginName, DateTime createTime)
        {
            bool state = false;
            UserCommunicationGrouptbDAO ucgDAO = new UserCommunicationGrouptbDAO();
            if (ucgDAO.saveComGroupInfo(comGroupName, comGroupType, userLoginName, createTime) == 1)
            {
                state = true;
            }
            return state;
        }

        /// <summary>
        /// 根据通讯组编号删除通讯组信息
        /// </summary>
        /// <param name="cgid"></param>
        /// <returns></returns>
        public bool delComGroupInfoById(int cgid)
        {
            bool state = false;
            UserCommunicationGrouptbDAO ucgDAO = new UserCommunicationGrouptbDAO();
            if (ucgDAO.delUserComGroupInfoById(cgid) == 1)
            {
                state = true;
            }
            return state;
        }

        /// <summary>
        /// 根据通讯组编号查找通讯组信息
        /// </summary>
        /// <param name="cgid"></param>
        /// <returns></returns>
        public UserCommunicationGrouptb findByComGroupId(int cgid)
        {
            UserCommunicationGrouptbDAO ucgDAO = new UserCommunicationGrouptbDAO();
            return ucgDAO.findByComGroupId(cgid);
        }

        /// <summary>
        /// 根据通讯组编号更改通讯组名称
        /// </summary>
        /// <param name="cgid"></param>
        /// <param name="newName"></param>
        /// <returns></returns>
        public bool updateComGroupInfoByGroupId(int cgid, string newName)
        {
            bool state = false;
            UserCommunicationGrouptbDAO ucgDAO = new UserCommunicationGrouptbDAO();
            if (ucgDAO.updateComGroupInfoByGroupId(cgid, newName) == 1)
            {
                state = true;
            }
            return state;
        }

        /// <summary>
        /// 根据用户登录名查找通讯组信息
        /// </summary>
        /// <param name="uln"></param>
        /// <returns></returns>
        public List<UserCommunicationGrouptb> findByUserLoginName(string uln)
        {
            UserCommunicationGrouptbDAO ucgDAO = new UserCommunicationGrouptbDAO();
            return ucgDAO.findByUserLoginName(uln);
        }
    }
}
